#include "BlockQueue.hpp"

void *Consume(void *args)
{
    data *d = static_cast<data *>(args);

    while (1)
    {
        sleep(1);
        Task _data = d->_bq->pop();
        std::cout << "消费成功: " << _data() << std::endl;
    }
    pthread_exit((void *)0);
}

void *Productor(void *args)
{
    data *d = static_cast<data *>(args);
    int _data = 1;
    while (1)
    {
        d->_bq->push({_data,_data+1});
        std::cout << "生产成功: " << _data << " " << _data + 1 << std::endl;
        _data++;
    }

    pthread_exit((void *)0);
}

int main()
{
    pthread_t t1, t2;
    BlockQueue<Task> bq;
    data d1 = {&bq, "Consume"};

    data d2 = {&bq, "Product"};
    pthread_create(&t1, nullptr, Consume, &d1);
    pthread_create(&t2, nullptr, Productor, &d2);


    pthread_join(t1,nullptr);
    pthread_join(t2,nullptr);
    return 0;
}